<template>
  <div class="main-box">
    <Nav :isBlack="false"></Nav>
    <div class="inner-box">
      <div class="content">
        <div class="title">
          {{ articleDetail.title }}
        </div>
        <div class="text-info">
          <div>{{ articleDetail.articleUploadDate }}</div>
          <el-divider direction="vertical"></el-divider>
          <div>{{ articleDetail.browse }}阅读</div>
          <el-divider direction="vertical"></el-divider>
          <div>{{ articleDetail.commit }}评论</div>

        </div>
        <div v-html="articleDetail.articleContent" v-if="articleDetail.articleContent"></div>
        <div class="article-bottom">
          <img src='@/assets/article_like.svg' class="article-like" v-if="!articleDetail.isLike" @click="articleLike" />
          <img src='@/assets/article_like_active.svg' class="article-like" v-else @click="articleLike" />
          <div class="article-like-number">{{ articleDetail.like }}</div>
          <div>觉得文章不错？赏个免费的赞吧</div>
          <el-divider></el-divider>
          <div class="article-bottom-inscribed">
            <div>本文禁止转载或摘编</div>
            <div style="color:rgba(60,135,243,1);cursor: pointer;">投诉和建议</div>
          </div>
        </div>
      </div>

    </div>
    <div class="inner-box" style="justify-content: normal">
      <div class="commit-box">
        <div class="commit-title">
          评论 {{ articleDetail.commits.length }}
        </div>
        <div style="margin-bottom:30px;">
          <SendCommit placeholder="发一条友善的评论吧" :avatar="userInfo.avatar" :type="1"></SendCommit>
        </div>
        <div class="commit">
          <Commit :avatar="item.avatar" :username="item.userName" :like='item.like' :date="item.date" type="commit"
            :content="item.content" v-for="(item, i) in articleDetail.commits" :key="i" :isLike="item.isLike" :commitId="item.commitId">
            <div class="reply">
              <Commit :avatar="item.avatar" :username="item.userName" :like='item.like' :date="item.date" type="reply"
                :content="item.content" :replyId="item.replyId" v-for="(item, i) in item.replys" :key="i"
                :isLike="item.isLike">
              </Commit>
            </div>
          </Commit>
        </div>
      </div>
    </div>
  </div>

</template>

<script setup>
import { ref } from 'vue'
import Nav from '@/components/Nav.vue'
import SendCommit from '@/components/article/SendCommit.vue'
import Commit from '@/components/article/Commit.vue'
import { communityDetail, communityArticleLike,  } from '@/api.js'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from "element-plus";
const route = useRoute()
const router = useRouter();
console.log();
const articleDetail = ref({})
const userInfo = JSON.parse(localStorage.getItem('userInfo'))
communityDetail(route.query.articleId, route.query.uuid).then((res) => {
  articleDetail.value = res
})

const htmlData = ref('')

const articleLike = () => {
  articleDetail.value.isLike = !articleDetail.value.isLike
  communityArticleLike(route.query.articleId, articleDetail.value.isLike, route.query.uuid).then(
    res => {
      if (res.success) {
        if (articleDetail.value.isLike) {
          articleDetail.value.like++;
          ElMessage({
            message: "点赞成功",
            type: "success",
          });
        }
        else {
          articleDetail.value.like--;
          ElMessage({
            message: "取消点赞成功",
            type: "success",
          });
        }
      }
    }
  )
}
</script>

<style scoped>
.main-box {
  background-color: #eee;
  position: absolute;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.inner-box {
  background-color: #fff;
  height: 100%;
  width: 1000px;
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;

}

.content {
  width: 700px;
}

.title {
  font-size: 28px;
  font-weight: 700;
  margin-top: 40px;
}

.text-info {
  display: flex;
  font-size: 14px;
  font-weight: 400;
  margin-top: 20px;
  color: #999;
  align-items: center;
  margin-bottom: 20px;
}

.article-bottom {
  margin-top: 30px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.article-like {
  width: 80px;
  height: 80px;
  cursor: pointer;
}

.commit-title {
  font-size: 20px;
  font-weight: bold;
  margin: 20px 0;
  align-self: flex-start;
}

.article-like-number {
  margin: 15px 0;
}

.article-bottom-inscribed {
  font-size: 14px;
  display: flex;
  margin-bottom: 20px;
  width: 100%;
  justify-content: space-between;
}

.commit-box {
  width: 800px;
}

.commit {
  display: flex;
  flex-direction: column;
}

.reply {
  margin-top: 15px;
}
</style>